package com.shengqi.xinnongren.work.ui.user.presenter;

import com.shengqi.xinnongren.common.base.BasePresenter;
import com.shengqi.xinnongren.common.config.network.Constants;
import com.shengqi.xinnongren.common.config.network.RetrofitHelper;
import com.shengqi.xinnongren.common.config.user.UserManager;
import com.shengqi.xinnongren.work.model.HttpRespond;
import com.shengqi.xinnongren.work.ui.Global;
import com.shengqi.xinnongren.work.ui.user.view.MyWalletView;

import org.json.JSONObject;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MyWalletPresenter extends BasePresenter<MyWalletView> {

    public void getBalance() {
        getView().showLoadingView();
        JSONObject jsonData = Constants.getJsonData(null, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getBalance(requestBody), s -> {
            getView().hideLoadingView();
            HttpRespond<String> httpResult = Global.getHttpResult(s);
            if (httpResult.result == 1) {
                getView().showBalanceRes(httpResult.data);
            } else
                getView().onRequestFailed(httpResult.message);
        });
    }
}
